package demo1;
import java.util.Arrays;

public class SeqList {
    private int[] elem;
    public int usideSize;//记录数组中有多少个元素
    private static final int DEFAULT_CAPICTY = 10;
    public SeqList(){
        int[] elem = new int [DEFAULT_CAPICTY];
    }

    //打印数组元素
    public void display(){
        for (int i = 0 ; i < usideSize;i++){
            System.out.println(this.elem[i]);
        }
    }

    //新增一个元素
    public void Add(int date){
        //首先判断是否满了
        if(isFull()){
            elem = Arrays.copyOf(elem,elem.length*2);
        }
        this.elem[usideSize] = date;
        usideSize++;

    }
    public boolean isFull(){
        return usideSize == elem.length;
    }
    // 判定是否包含某个元素
    public boolean contains(int toFind) {
        for (int i = 0; i < usideSize; i++) {
            if(this.elem[i] == toFind){
                return true;
            }
        }

        return false;
    }
    // 查找某个元素对应的位置
    public int indexOf(int toFind) {
        for (int i = 0; i < usideSize; i++) {
            if ((elem[i] == toFind)){
                return i;
            }
        }

        return -1;
    }
    //获取pos位置的元素
    public int get(int pos){
        //判断下标是否合法
        if(pos >= usideSize || pos < 0){
            throw new posoutBoundsException("pos获取数据不合法！");
        }
        return this.elem[pos];
    }
}
